<html>
<head>
	<title>Excersise 2</title>
	<link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
	<div id="js-console"></div>
	<script src="scripts/js-console.js"></script>
	<script>

	function AreBracketsCorrect(inStr)
	{
		var  str = new String(inStr);
		var i;
		var isCorrect;
		var counterOp=0;
		var counterCl=0;
				if ((str.indexOf(')',0))<(str.indexOf('(',0)) || (str.lastIndexOf('(',str.length))>(str.lastIndexOf(')',str.length)))
				{
					return 	jsConsole.writeLine("expresion: '" + str + "', is not correct");
				}
				else
				{
						for(i=0;i<str.length;i++)
						{
							if((str.indexOf(')',(i))!=-1))
							{
								i = str.indexOf(')',(i));
								counterCl++;
							}
						}
						for(i=0;i<str.length;i++)
						{
							if((str.indexOf('(',(i))!=-1))
							{
							i=str.indexOf('(',(i));
								counterOp++;
							}
						}						
						
						if (counterOp===counterCl)
						{
							jsConsole.writeLine("expresion: '" + str + "', is correct");				
						}
						else
						{
							jsConsole.writeLine("expresion: '" + str + "', is not correct");
						}
				}
	}
	AreBracketsCorrect('asdsad((a+b)/5-d)');
	AreBracketsCorrect(')(a+b))');
	AreBracketsCorrect('((()))(())');
	</script>
</body>
</html>
